package com.youedata.modular.controller;

import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youedata.base.pojo.page.LayuiPageFactory;
import com.youedata.base.tips.DCResponse;
import com.youedata.modular.entity.JhTravelInfo;
import com.youedata.modular.entity.LegalServiceInfo;
import com.youedata.modular.model.dto.JhTravelInfoDTO;
import com.youedata.modular.service.IJhTravelInfoService;
import com.youedata.modular.service.ITravelInfoImgRelService;
import com.youedata.sys.core.util.UserHolder;
import com.youedata.util.ToolUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 吃在玩在建湖表控制器
 *
 * @author hst
 * @date 2021-07-19 18:23:03
 */
@Controller
@Api(value = "/jhTravelInfo", tags = "吃在玩在建湖表管理")
@RequestMapping("/jhTravelInfo")
public class JhTravelInfoController {

    private String PREFIX = "/jhTravelInfo";

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private IJhTravelInfoService jhTravelInfoService;

    /**
     * 新增
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/addItem")
    @ApiOperation(value = "新增")
    public DCResponse<Void> addItem(JhTravelInfoDTO jhTravelInfoDto) {
        this.jhTravelInfoService.saveSelective(jhTravelInfoDto);
        return DCResponse.ok(null);
    }

    /**
     * 根据主键删除
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/delete")
    @ApiOperation("删除")
    public DCResponse<Void> delete(@RequestParam("id") String id) {
        this.jhTravelInfoService.removeById(id);
        return DCResponse.ok(null);
    }

    /**
     * 修改
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/editItem")
    @ApiOperation("根据ID修改信息")
    public DCResponse<Void> editItem(JhTravelInfoDTO jhTravelInfoDto) {
        this.jhTravelInfoService.updateJhTravelInfo(jhTravelInfoDto);
        return DCResponse.ok(null);
    }

    /**
     * 根据主键查询单条详情
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @PostMapping("/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData detail(@RequestParam("id") String id) {

        return ResponseData.success(this.jhTravelInfoService.detailById(id, "N"));
    }

    /**
     * 分页查询列表
     *
     * @author hst
     * @date 2021-07-19
     */
    @ResponseBody
    @GetMapping("/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
            @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(JhTravelInfoDTO jhTravelInfoDto) {
        JhTravelInfo jhTravelInfo = new JhTravelInfo();

        //过滤空字符串
        jhTravelInfoDto.setName(StringUtils.isEmpty(jhTravelInfoDto.getName()) ? null : jhTravelInfoDto.getName());
        jhTravelInfoDto.setType(StringUtils.isEmpty(jhTravelInfoDto.getType()) ? null : jhTravelInfoDto.getType());

        BeanUtils.copyProperties(jhTravelInfoDto, jhTravelInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        String name = jhTravelInfo.getName();
        String type = jhTravelInfo.getType();

        //根据条件查询
        // page.setRecords(this.jhTravelInfoService.page(page, Wrappers.query(jhTravelInfo)).getRecords());
        page.setRecords(this.jhTravelInfoService.queryNameFuzzy(page, name, type));

        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 跳转到主页面
     *
     * @author hst
     * @Date 2021-07-19
     */
    @RequestMapping()
    public String index() {
        return PREFIX + "/jhTravelInfo.html";
    }

    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-07-19
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/jhTravelInfo_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-07-19
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/jhTravelInfo_edit.html";
    }

}
